package org.sidora.core.util;



import java.util.HashMap;
import java.util.Map;


/**
 * Servidor de factories
 * @author Enric Tartera, Juan Manuel Gimeno, Roger Masgoret
 * @version 1.0
 */
public final class FactoryPool { // A singleton
	
	  private static FactoryManager pool = new FactoryManager();
	  
	  public static void addFactory(Object obj, AbstractFactory inv) {
	      pool.add(obj, inv);
	  }
	
	  public static AbstractFactory getFactory(String id)  throws Exception {
	    return (AbstractFactory)pool.get(id);
	  }

 }// end FactoryPool


/**
 * <p>Gestor d'inventaris</p>
 * Classe que complementa InventoryPool. Implementa una col.lecció -un mapa- dels inventaris
 * referenciats per un objecte-clau, En el cas de ContextInventory l'objecte candidat serà el 
 * que conté l'inventari
 * 
 * <br /><br />
 * 
 * @author Enric Tartera, Anna Arnalot, Equip Sidora 
 * @version 0.4
 */

class FactoryManager {
	
	private Map<Object, AbstractFactory> factories = 
		new HashMap<Object,AbstractFactory>();
	
	public void add(Object obj, AbstractFactory inv) {
	    factories.put(obj, inv);
	  }
	  
	public AbstractFactory get(Object obj) {
		
		if (factories.containsKey(obj)){
		return factories.get(obj);
		}
		else throw new RuntimeException("Sense Factoria adequada");
	    // return null; // Delayed failure
	  }
	
	
	 }

